package com.minelx.woods.pc.service;

import com.alibaba.fastjson.JSON;
import com.minelx.httpclient.core.request.IResponse;
import com.minelx.woods.pc.service.mapper.AuthRequestMapper;
import com.minelx.woods.pc.service.mapper.ReviewRequestMapper;
import com.minelx.woods.pc.service.mapper.TaskRequestMapper;

import java.nio.charset.StandardCharsets;

public class WoodsSession {

	public static final String TOKEN_KEY = "token";

	private final String token;

	public WoodsSession(String user, String password) {
		String responseAsText = new AuthRequestMapper()
				.postRequestToken(user, password)
				.contentAsText(StandardCharsets.UTF_8);
		token = JSON.parseObject(responseAsText).getString(TOKEN_KEY);
	}

	public TaskService taskService() {
		return new TaskService(new TaskRequestMapper(), token);
	}

	public ReviewService reviewService() {
		return new ReviewService(new ReviewRequestMapper(), token);
	}
}
